<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el" %>
<%@ taglib uri="ford-arg/tags" prefix="ft" %>

<script language="JavaScript" src="./scripts/CalendarPopup.js"></script>  
<script language="JavaScript" src="./scripts/popups.js"></script>
<script language="javascript" src="./scripts/ajaxSearch.js"></script>

<script language="javascript">

	var cal = new CalendarPopup(); 
	cal.showNavigationDropdowns();
	cal.setMonthNames('<bean:message key="label.month.january"/>',
						'<bean:message key="label.month.february"/>',
						'<bean:message key="label.month.march"/>',
						'<bean:message key="label.month.april"/>',
						'<bean:message key="label.month.may"/>',
						'<bean:message key="label.month.june"/>',
						'<bean:message key="label.month.july"/>',
						'<bean:message key="label.month.august"/>',
						'<bean:message key="label.month.september"/>',
						'<bean:message key="label.month.october"/>',
						'<bean:message key="label.month.november"/>',
						'<bean:message key="label.month.december"/>');
	cal.setDayHeaders('<bean:message key="label.day.sunday.capital"/>',
						'<bean:message key="label.day.monday.capital"/>',
						'<bean:message key="label.day.tuesday.capital"/>',
						'<bean:message key="label.day.wednesday.capital"/>',
						'<bean:message key="label.day.thursday.capital"/>',
						'<bean:message key="label.day.friday.capital"/>',
						'<bean:message key="label.day.saturday.capital"/>');
	cal.setTodayText('<bean:message key="label.today"/>');

	function findRequests() {
		document.RequestsForm.action = "RequestsActionFind.do";
		document.RequestsForm.section.value = "find";
		document.RequestsForm.editBlocked.value = "false";
		document.RequestsForm.submit();	
	}
	
	function closeRequest(){
		document.RequestsForm.action = "RequestsActionClose.do";
		document.RequestsForm.section.value = "close";
		document.RequestsForm.editBlocked.value = "false";
	}
	
	function viewObs(rowNum){
		window.open("RequestsActionViewObs.do?selectedIndex="+rowNum, "", "width=570px, height=210px, resizable, status=1,scrollbars=1");
	}
	
	function clearFindFilds(){
		document.getElementById('supplierCodeFind').value="";
		document.getElementById('partPrefix').value="";    
		document.getElementById('partBase').value="";
		document.getElementById('partSuffix').value="";
		document.getElementById('dateFrom').value="";
		document.getElementById('dateTo').value="";  
		document.getElementById('userCode').value="";
		document.getElementById('supplierNameFind').value="";
		document.getElementById('supplierClassFind').selectedIndex=0;
		document.getElementById('commodity').selectedIndex=0;
		document.getElementById('status').selectedIndex=0;
		document.getElementById('partClass').selectedIndex=0;
		document.getElementById('dateFilter').selectedIndex=0;
		document.getElementById('userField').selectedIndex=0;
		document.RequestsForm.section.value = "cleanFind";
		document.RequestsForm.editBlocked.value = "false";
	}
	
	function cleanCreateFields(){    
		document.RequestsForm.action="cleanCreateFields.do"
		document.RequestsForm.editBlocked.value = "false";
		document.RequestsForm.section.value = "cleanCreate";
		document.RequestsForm.submit();
	}
		
	function editRequestItems(){
		document.RequestsForm.action = "RequestsActionEditItems.do";
		document.RequestsForm.section.value = "editItems";
		document.RequestsForm.editBlocked.value = "false";
	}
	
	function editRequest(rowNum){
		document.RequestsForm.action = "RequestsActionEditRequest.do";
		document.RequestsForm.section.value = "editRequest";
		document.RequestsForm.editBlocked.value = "true";
		document.RequestsForm.selectedIndex.value = rowNum;					
	}
	
	function deleteRequest(rowNum){
		if(confirm('<bean:message key="request.confirmDelete" />')){
			document.RequestsForm.action = "RequestsActionDelete.do";
			document.RequestsForm.section.value = "delete";
			document.RequestsForm.editBlocked.value = "false";
			document.RequestsForm.selectedIndex.value = rowNum;
			document.RequestsForm.submit();		
		}else{
			return false;
		}
	}
	
	function createUpdateRequest(){
		document.RequestsForm.action = "RequestsActionCreate.do";
		document.RequestsForm.section.value = "createUpdate";
		document.RequestsForm.submit();					
	}
	
	
</script>
	
<table>
	<tr>
		<td colspan="2"><h2><bean:message key="request.label.title"/></h2></td>
	</tr>
</table>
<br/>
<html:form action="/RequestsActionInit">
<html:hidden property="section" />
<html:hidden property="editBlocked" />
<html:hidden property="selectedIndex"/>

	<%-- Mantiene el numero de pagina despues del submit --%>
	<ft:saveActivePageNumber/>

	<bean:define id="requestTitle">
		<bean:message key="request.label" />
	</bean:define>
	<bean:define id="supplierTitle">
		<bean:message key="supplier.label.supplier" />
	</bean:define>
	<bean:define id="statusTitle">
		<bean:message key="request.label.status" />
	</bean:define>
	<bean:define id="effDateTitle">
		<bean:message key="request.label.tableHeader.date" />
	</bean:define>
	<bean:define id="creationTitle">
		<bean:message key="user.label.creation" />
	</bean:define>
	<bean:define id="closureTitle">
		<bean:message key="request.label.tableHeader.closure" />
	</bean:define>
	<bean:define id="obsTitle">
		<bean:message key="request.label.tableHeader.obs" />
	</bean:define>
	<bean:define id="actionsTitle">
		<bean:message key="request.label.tableHeader.actions" />
	</bean:define>
	<table style="width: 850px;" class="no_border">
		<tr>
			<td class="text_blue_bold align_left" style="width: 9%;">
				<bean:message key="part.label.filter" />
			</td>
			<td style="width: 41%;"></td>
			<td style="width: 7%;"></td>
			<td style="width: 43%;"></td>
			
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="supplier.label.supplier" />
			</td>
			<td class="align_left">
				<html:select property="supplierClassFind" styleId="supplierClassFind">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="partClassColl"
								  property="value"
								  labelProperty="label" />
				</html:select>
				<html:text styleId="supplierCodeFind" property="supplierCodeFind" maxlength="5" size="7"/>
				<html:text property="supplierNameFind" styleId="supplierNameFind" maxlength="70" size="25"></html:text>
			</td>
			<td class="text_blue_bold align_left">
				<bean:message key="request.label.date"/>
			</td>
			<td class="text_blue_bold align_left">
				<html:select property="dateFilter" styleId="dateFilter">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="dateFields"
								  property="value"
								  labelProperty="label" />
				</html:select>
				<bean:message key="request.label.from"/>
				<html:text styleId="dateFrom" property="dateFrom" maxlength="10" size="9"/><A name="dateFromAnchor"> </A><html:button property="calendar" onclick="cal.select(document.RequestsForm.dateFrom,'dateFromAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
				<bean:message key="request.label.to"/>&nbsp;
				<html:text styleId="dateTo" property="dateTo" maxlength="10" size="9"/><A name="dateToAnchor"> </A><html:button property="calendar" onclick="cal.select(document.RequestsForm.dateTo,'dateToAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="commodity.label" />
			</td>
			<td class="text_blue_bold align_left"> 
				<html:select property="commodityCode" styleId="commodity">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="commColl"
								  property="eesp02CommodityNumberK"
								  labelProperty="eesp02CommodityNameN" />
				</html:select>
			</td>
			<td class="text_blue_bold align_left">
				<bean:message key="label.user" />:
			</td>
			<td class="text_blue_bold align_left"> 
				<html:select property="userField" styleId="userField">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="userFields"
								  property="value"
								  labelProperty="label" />
				</html:select>
				<html:text property="userCode" styleId="userCode" size="10"></html:text>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="part.label" />
			</td>
			<td class="align_left" colspan="3"> 
				<html:select property="partClass" styleId="partClass">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="partClassColl"
								  property="value"
								  labelProperty="label" />
				</html:select> 
				<html:text styleId="partPrefix" property="prefix" maxlength="10" size="9"/>&nbsp;
				<html:text styleId="partBase" property="base" maxlength="10" size="9"/>&nbsp;
				<html:text styleId="partSuffix" property="suffix" maxlength="10" size="9"/>
				<html:button property="parF" onclick="searchNamePart('lookupedPart','partClass','partPrefix','partBase','partSuffix');" styleClass="button_small" style="width:20px;">...</html:button>
				<html:button property="findParts" onclick="findPartPopup('supplierClassFind', 'supplierCodeFind', 'partClass', 'partPrefix', 'partBase', 'partSuffix');" styleClass="button_small" style="width:20px;">?</html:button>				
				<div style="display:inline;" id="lookupedPart" />
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="request.label.status"/>
			</td>
			<td class="align_left"> 
				<html:select property="status" styleId="status">
					<html:option value="-1"><bean:message key="label.allOption" /></html:option>
					<html:options collection="statusColl"
								  property="value"
								  labelProperty="label" />
				</html:select>
			</td>
			<td class="text_blue_bold align_right" colspan="2">
				<html:button property="find" onclick="findRequests();" styleClass="button"><bean:message key="label.find" /></html:button>&nbsp;			
				<input type="button" value="<bean:message key="label.clean"/>" class="button" onclick="clearFindFilds();" />
			</td>
		</tr>
	</table>
	<br/>
	<div class="edit_out align_center" style="width:800px;" >
	<div class="edit align_center" style="width: 800px;" >
		<table style="width: 850px;" class="no_border">
			<tr>
				<td class="text_blue_bold align_left" colspan="1" width="15%">
					<bean:message key="supplier.label.supplier" />
				</td>
				<td class="align_left" colspan="3" width="65%">
					<logic:equal name="RequestsForm" property="editBlocked" value="false">
						<html:select property="supplierClass" styleId="supplierClass">
						<html:option value="-1"><bean:message key="label.allOption" /></html:option>
						<html:options collection="partClassColl"
									  property="value"
									  labelProperty="label" />
						</html:select>&nbsp; 
						<html:text styleId="supplierCode" property="supplierCode" maxlength="50" size="20"/>&nbsp;
						<html:button property="suppName" onclick="searchNameSupplier('supplierName','supplierCode','supplierClass');" styleClass="button_small">...</html:button>
						<html:button property="findSupp" onclick="findSupplierPopup('supplierClass','supplierCode');" styleClass="button_small" style="width:20px;">?</html:button>&nbsp;	
						<div id="supplierName" title="supplierName" style="display: inline; align: left;"></div>
					</logic:equal>
					<logic:notEqual name="RequestsForm" property="editBlocked" value="false">
						<bean:write name="RequestsForm" property="supplierClass"/>&minus;
						<bean:write name="RequestsForm" property="supplierCode"/>
					</logic:notEqual>
				</td>
				<td class="text_blue_bold align_center" width="20%">
					<html:button styleClass="button_small" property="update" onclick="createUpdateRequest();"><bean:message key="label.createUpdate" /></html:button>
				</td>
			</tr>
			<tr>
				<td class="text_blue_bold align_left">
					<bean:message key="request.label.effDate" />
				</td>
				<td class="align_left" colspan="3"> 
					<html:text styleId="effDate" property="effDate" maxlength="10" size="12"/><A name="effDateAnchor"> </A><html:button property="calendar" onclick="cal.select(document.RequestsForm.effDate,'effDateAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>
				</td>
				<td class="text_blue_bold align_center">
					<input type="button" value="<bean:message key="label.new"/>" class="button_small" onclick="cleanCreateFields()" />			
				</td>
			</tr>
			<tr>
				<td class="text_blue_bold align_left">
					<bean:message key="request.label.supplierContact" />
				</td>
				<td class="align_left">
					<html:text property="supplierContact" styleId="supplierContact" maxlength="70" size="40"></html:text>
				</td>
				<td></td>
			</tr>
		</table>
	</div>
	</div>	
	<br />
		
	<table class="no_border" style="width: 870px;">
		<tr>
			<td>
				<display-el:table 	class="table1" style="width: 870px;" cellpadding="5" uid="request"
									 pagesize="15" name="sessionScope.RequestsForm.requestColl" 
									excludedParams="*" requestURI="RequestsActionPaginate.do" >
					<display-el:column title="${requestTitle}" property="eesr01RequestNumberK" style="width: 10%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right"/>
					<display-el:column title="${supplierTitle}" property="teess01Supplier.eess01SupplierNameN" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right"/>
					<display-el:column title="${statusTitle}" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<logic:equal name="request" property="eesr01RequestStatusCodeC" value="P">
							<bean:message key="request.label.pending"/>
						</logic:equal>
						<logic:equal name="request" property="eesr01RequestStatusCodeC" value="R">
							<bean:message key="request.label.rejected"/>
						</logic:equal>
						<logic:equal name="request" property="eesr01RequestStatusCodeC" value="I">
							<bean:message key="request.label.inProcess"/>
						</logic:equal>
						<logic:equal name="request" property="eesr01RequestStatusCodeC" value="C">
							<bean:message key="request.label.closed"/>
						</logic:equal>
					</display-el:column>
					<display-el:column title="${effDateTitle}" property="eesr01RequestIssueDateY" decorator="ar.com.ford.it.fullEconomics.view.displaytag.DateDecorator"  style="width: 10%;"  class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right" />
					<display-el:column title="${creationTitle}" decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right" >
						<bean:write name="request" property="eesr01CreateUserC"/><br />
						<bean:write name="request" property="eesr01CreateS"/>
					</display-el:column>
					<display-el:column title="${closureTitle}" decorator="ar.com.ford.it.fullEconomics.view.displaytag.CostStructureItemColumnDecorator" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right" >
						<logic:empty name="request" property="eesr01RequestClosureUserC">
							<html:submit property="requestMapped(${request_rowNum})" styleClass="button" onclick="closeRequest();"><bean:message key="request.label.close" /></html:submit>
						</logic:empty>
						<logic:notEmpty name="request" property="eesr01RequestClosureUserC">
							<bean:write name="request" property="eesr01RequestClosureUserC"/><br />
							<bean:write name="request" property="eesr01RequestClosureS"/>
						</logic:notEmpty>
					</display-el:column>
					<display-el:column title="${obsTitle}" class="cell1 text_bold border1_right border1_top align_center" headerClass="header border_right">
							<html:button property="req" styleClass="button" onclick="viewObs(${request_rowNum});"><bean:message key="request.label.view" /></html:button>
					</display-el:column> 
					<display-el:column title="${actionsTitle}"  style="width: 10%;" class="cell1 text_bold border1_right border1_top align_left" headerClass="header border_right">
						<html:image property="ed" alt="${edit}" onclick="editRequest(${request_rowNum});" page="/images/edit.gif" style="width:20px" />&nbsp;
						<div style="cursor: pointer; display: inline;"><html:img alt="${delete}"  onclick="deleteRequest(${request_rowNum});" page="/images/erase.gif" style="width:20px" />&nbsp;</div>
						<html:submit property="requestMapped(${request_rowNum})" onclick="editRequestItems();" styleClass="button"><bean:message key="request.label.items"/></html:submit>
					</display-el:column>
				</display-el:table>
			</td>		
		</tr>
	</table>
</html:form>